clear all
cd "C:\Users\ot3\Documents\TeacherDeseg\Census"

set more off

clear
quietly infix                ///
  int     year      1-4      ///
  byte    datanum   5-6      ///
  double  serial    7-14     ///
  double  hhwt      15-24    ///
  byte    region    25-26    ///
  byte    statefip  27-28    ///
  byte    urban     29-29    ///
  byte    gq        30-30    ///
  int     pernum    31-34    ///
  double  perwt     35-44    ///
  byte    sex       45-45    ///
  int     age       46-48    ///
  int     birthyr   49-52    ///
  byte    race      53-53    ///
  int     raced     54-56    ///
  byte    hispan    57-57    ///
  int     hispand   58-60    ///
  int     bpl       61-63    ///
  long    bpld      64-68    ///
  byte    educ      69-70    ///
  int     educd     71-73    ///
  byte    empstat   74-74    ///
  byte    empstatd  75-76    ///
  byte    labforce  77-77    ///
  int     occ1950   78-80    ///
  int     ind1950   81-83    ///
  long    inctot    84-90    ///
  long    ftotinc   91-97    ///
  long    incwage   98-103   ///
  int     poverty   104-106  ///
  int     migplac5  107-109  ///
  byte    work5yr   110-110  ///
  byte    milit5yr  111-111  ///
  byte    coll5yr   112-112  ///
  int     occ5yr95  113-115  ///
  int     ind5yr    116-118  ///
  using `"usa_00063.dat"'

replace hhwt     = hhwt     / 100
replace perwt    = perwt    / 100

format serial   %8.0f
format hhwt     %10.2f
format perwt    %10.2f


*Note: Data already restricted to non-Hispanic, black or white

*Race, sex
recode race (1=0)(2=1)(else=.), gen(black)
recode sex (1=1)(2=0), gen(male)


*Current residence regions
g south=inlist(statefip, 1, 5, 12, 13, 22, 28, 37, 45, 47, 48, 51)  
replace south=. if statefip==.

*Residence 5 years ago
drop if migplac5==99 | migplac5==900 //residence 5 yrs ago notspecified/confidential or abroad
g south5=inlist(migplac5, 1, 5, 12, 13, 22, 28, 37, 45, 47, 48, 51)

*Tag cross-region migrants
g migrate=south5!=south



*Current employment category
drop if occ1950==999 

recode empstat (1=0)(2 3=1), gen(outlforce)

recode occ1950 (93=1)(else=0), gen(teacher)
replace teacher=0 if outlforce==1 //respondents report an occupation if they have wroked in past 10 years, even if not working now

recode occ1950 (0/92 94/99=1)(else=0), gen(prof)  
replace prof=0 if outlforce==1 

g nonprof=teacher==0 & prof==0 & outlforce==0

g migrant_teacher=migrate==1 & teacher==1

*Employment category 5 years ago
drop if work5yr==9  //"not reported"
recode occ5yr95 (93=1)(else=0), gen(teacher5)


*Define race-by-region groups
g blackXsouth5=black*south5

save OccFiveYrs, replace



***Table 5**
*means
use OccFiveYrs, clear
keep if teacher5==1 //restrict sample to people who were teachers in 1965
keep if  teacher==0 | (teacher==1 & migrate==1) //further restrict to people who had either left teaching by 1970, or had continued teaching but migrated across regions 

foreach x of varlist prof nonprof migrant_teacher outlforce {

qui reg `x' if black==1 & south5==1
est sto `x'SB

qui reg `x' if black==0 & south5==1
est sto `x'SW

qui reg `x' if black==1 & south5==0
est sto `x'NB

}
outreg2 [*] using T1,  dec(3)   nor2 noas nose replace 



*Differences
use OccFiveYrs, clear
keep if teacher5==1 //restrict sample to people who were teachers in 1965
keep if  teacher==0 | (teacher==1 & migrate==1) //further restrict to people who had either left teaching by 1970, or had continued teaching but migrated across regions 

foreach x of varlist prof nonprof migrant_teacher outlforce {

qui reg `x' black if south5==1
est sto `x'DRace

qui reg `x' south5 if black==1
est sto `x'DRegion

}
outreg2 [*] using T1,  dec(3)   nor2  replace nocons noobs





*Regression described in text testing whether southern black exited disproportinoately
use OccFiveYrs, clear 
g disrupted=(teacher5==1 & teacher==0) | (teacher5==1 & teacher==1 & migrate==1)
reg disrupted black south5 blackXsouth5 , robust
sum disrupted if blackXsouth5==0



